package cn.minhx.domain.activity.service.trial.node;

import cn.minhx.domain.activity.model.entity.MarketProductEntity;
import cn.minhx.domain.activity.model.entity.TrialBalanceEntity;
import cn.minhx.domain.activity.service.trial.AbstractGroupBuyMarketSupport;
import cn.minhx.domain.activity.service.trial.factory.DefaultActivityStrategyFactory;
import cn.minhx.types.design.tree.StrategyHandler;
import cn.minhx.types.enums.ResponseCode;
import cn.minhx.types.exception.AppException;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 拼团商品查询试算服务-ErrorNode
 *
 * @author min
 */
@Slf4j
@Service
public class ErrorNode extends AbstractGroupBuyMarketSupport {

	@Override
	protected TrialBalanceEntity doApply(MarketProductEntity requestParameter,
			DefaultActivityStrategyFactory.DynamicContext dynamicContext) throws Exception {
		log.info("拼团商品查询试算服务-ErrorNode requestParameter:{}", JSON.toJSONString(requestParameter));
		// 无营销配置
		if (null == dynamicContext.getGroupBuyActivityDiscountVO() || null == dynamicContext.getSkuVO()) {
			log.info("商品无拼团营销配置 {}", requestParameter.getGoodsId());
			throw new AppException(ResponseCode.E0002);
		}
		return TrialBalanceEntity.builder().build();
	}

	@Override
	public StrategyHandler<MarketProductEntity, DefaultActivityStrategyFactory.DynamicContext, TrialBalanceEntity> next(
			MarketProductEntity requestParameter, DefaultActivityStrategyFactory.DynamicContext dynamicContext)
			throws Exception {
		return defaultStrategyHandler;
	}
}
